﻿
namespace CoProjectDF.Repository
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.Composition;
    using CoProjectModel;
    using IdeaBlade.Application.Framework.Core.Persistence;
    using IdeaBlade.EntityModel;

    [Export(typeof(IUserRepository))]
    public class UserRepository : IUserRepository
    {
        private IEntityManagerProvider<CoProjectEntities> EntityManagerProvider { get; set; }
        private CoProjectEntities Manager { get { return EntityManagerProvider.Manager; } }

        [ImportingConstructor]
        public UserRepository(IEntityManagerProvider<CoProjectEntities> entityManagerProvider)
        {
            EntityManagerProvider = entityManagerProvider;
        }

        public INotifyCompleted GetUsers(Action<IEnumerable<User>> onSuccess = null,
                                         Action<Exception> onFail = null)
        {
            var q = Manager.Users;
            var op = q.ExecuteAsync();
            return op.OnComplete(onSuccess, onFail);
        }
    }
}
